#!/usr/bin/env python
# coding: utf-8

# In[ ]:


import numpy as np
# 定义for循环计算用的函数
def veg_sum(X,Y):
    # 定义日期列表
    date=['7/28','7/29','7/30']    
    # 定义起始值0
    vegsum=[] 
    # 循环 
    for i in range(3):
        sum = 0
        for j in range(3):
            # 矩阵相乘 相加
            sum += (X[i,j] * Y[j])
        vegsum.append(sum)
    print(vegsum)
    for i in range(3):
        print('日期:',date[i],'金额:',vegsum[i])
X=np.array([[1.2,1.5,1.8],[1.3,1.4,1.9],[1.1,1.6,1.7]])
Y=np.array([[5,10,9]]).T
get_ipython().run_line_magic('timeit', 'res = veg_sum(X,Y)')


# In[ ]:


def veg_sum_dot(X,Y):
    # 点乘
    vegsum=np.dot(X,Y)
    date=['7/28','7/29','7/30']
    for i in range(3):
        print('日期:',date[i],'金额:',vegsum[i])
X=np.array([[1.2,1.5,1.8],[1.3,1.4,1.9],[1.1,1.6,1.7]])
Y=np.array([5,10,9]).T
get_ipython().run_line_magic('timeit', 'res=veg_sum_dot(X,Y)')

